<template>
  <b-table
    ref="table"
    :export-config=" {use: true,select: '招标定标明细', all: '招标定标明细'}"
    :columns="columns"
    :scroll="{ x: 1300 }"
    :request="loadData"
  >
    <template slot="index" slot-scope="text, record, index">{{ index + 1 }}</template>
    <template
      v-for="col in ['registerMoney', 'contact', 'contactPhone','tandardCost','isRecommendWinStr','remark']"
      :slot="col"
      slot-scope="text, record, index"
    >
      <div :key="col">
        <template v-if="state !== 3">
          <b-input v-if="col === 'remark'" v-model="record[col]" @blur="handleChange(record)" />
          <b-input-number
            class="requiredFormItem"
            v-else-if="col === 'registerMoney' "
            v-model="record[col]"
            :precision="6"
            @blur="handleChange(record)"
          />
          <b-input-number
            class="requiredFormItem"
            v-else-if="col === 'tandardCost'"
            v-model="record[col]"
            :precision="2"
            @blur="handleChange(record)"
          />
          <b-input
            class="requiredFormItem"
            v-else-if="col === 'contact' || col === 'contactPhone' "
            v-model="record[col]"
            @blur="handleChange(record)"
          />
          <span v-if="col === 'isRecommendWinStr'" class="requiredFormItem">
                <a-select @change="handleChange(record)" v-model="record['isRecommendWin']" placeholder="请选择">
                    <a-select-option :value="0">否</a-select-option>
                    <a-select-option :value="1">是</a-select-option>
                </a-select>
              </span>
        </template>
        <template v-else>
          {{ text }}
        </template>
      </div>
    </template>
  </b-table>
</template>
<script>
import { editByDetail, queryDetailsById } from '@/api/material/procurement/tender'

const data = []
export default {
  name: 'a' + Date.now(),
  props: {
    state: {
      type: Number
    },
    id: {
      type: String
    }
  },
  data() {
    return {
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'index' },
          width: '100px'
        },
        {
          title: '投标单位名称',
          dataIndex: 'supplierName',
          width: 150
        },
        {
          title: '投标单位编码',
          dataIndex: 'supplierCode',
          width: 150
        },
        {
          title: '注册资金(万元)',
          dataIndex: 'registerMoney',
          scopedSlots: { customRender: 'registerMoney' },
          width: 150
        },
        {
          title: '联系人',
          dataIndex: 'contact',
          scopedSlots: { customRender: 'contact' },
          width: 150
        },
        {
          title: '联系电话',
          dataIndex: 'contactPhone',
          scopedSlots: { customRender: 'contactPhone' },
          width: 150
        },
        {
          title: '投标总价（税前/元）',
          dataIndex: 'settleAmountWithTax',
          width: 150
        },
        {
          title: '投标总价（税后/元）',
          dataIndex: 'sumulativeAmountWithoutTax',
          width: 150
        },
        {
          title: '标准成本（元）',
          dataIndex: 'tandardCost',
          scopedSlots: { customRender: 'tandardCost' },
          width: 150
        },
        {
          title: '采购成本降低率(%)',
          dataIndex: 'lowCost',
          width: 150
        },
        {
          title: '是否中标',
          dataIndex: 'isRecommendWinStr',
          scopedSlots: { customRender: 'isRecommendWinStr' },
          width: 150
        },
        {
          title: '备注',
          dataIndex: 'remark',
          scopedSlots: { customRender: 'remark' },
          width: 250
        }
      ],
      loadData: params => queryDetailsById({}, Object.assign(params, { baseId: this.id }))
    }
  },
  methods: {
    handleChange(row) {
      if (row['tandardCost'] && row['sumulativeAmountWithoutTax']) {
        row['lowCost'] = (row['tandardCost'] - row['sumulativeAmountWithoutTax']) / row['tandardCost'] * 100
        row['lowCost'] = row['lowCost'].toFixed(2)
      }
      this.save(row)
    },
    async save(row) {
      let res = await editByDetail({}, row)
      if (res.code === this.SUCCESS_CODE) {
        this.$emit('update')

      }
    }
  }
}
</script>
